import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import { useStore } from "vuex";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/login",
    name: "Login",
    component: () => import("../views/Login.vue"),
  },
  {
    path: "/assistant",
    name: "Assistant",
    component: () => import("../views/Assistant.vue"),
    redirect: "/assistant/chat",
    children: [
      {
        path: "chat",
        name: "Chat",
        component: () => import("../views/components/Chat/chatHome.vue"),
      },
      {
        path: "document",
        name: "DocumentEditor",
        component: () => import("../views/components/Document/document.vue"),
      },
      {
        path: "tasks",
        name: "TaskList",
        component: () => import("../views/components/Tasks/tasks.vue"),
      },
      {
        path: "settings",
        name: "SettingsPanel",
        component: () => import("../views/components/Settings/settings.vue"),
      },
    ],
  },
  {
    path: "/:pathMatch(.*)*",
    redirect: "/login",
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

// router.beforeEach((to, from, next) => {
//   const store = useStore();
//   const isAuthenticated = store.getters.isAuthenticated;

//   if (to.path === "/login") {
//     if (isAuthenticated) {
//       next("/assistant");
//     } else {
//       next();
//     }
//   } else {
//     if (isAuthenticated) {
//       next();
//     } else {
//       next("/login");
//     }
//   }
// });

export default router;
